package hhpoll.service.ws;

import java.util.Date;
import java.util.List;

import hhpoll.domain.Poll;
import hhpoll.domain.PollItem;
import hhpoll.domain.PollParticipant;
import hhpoll.service.PollService;
import hhpoll.service.context.RequestContext;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService
public class PollServiceWS {
	
	private PollService pollService;
	
	public PollServiceWS (PollService pollService) {
		this.pollService = pollService;
	}
	
	@WebResult(name="poll")
	public Poll createPoll (@WebParam(name="context")RequestContext context,
							@WebParam(name="poll")Poll poll) {
		//return pollService.createPoll(RequestContext.getContext(), poll);
		return pollService.createPoll(context, poll);
	}
	
	@WebResult(name="poll")
	public Poll getPoll (@WebParam(name="context")RequestContext context,
			             @WebParam(name="pollId")Long pollId,
			             @WebParam(name="participantDetails")boolean participantDetails,
			             @WebParam(name="itemDetails")boolean itemDetails) {
		//return pollService.getPoll(RequestContext.getContext(), pollId);
		return pollService.getPoll(context, pollId, participantDetails, itemDetails);
	}
	
	@WebResult(name="participant")
	public PollParticipant vote (@WebParam(name="context")RequestContext context, 
	                             @WebParam(name="pollId")Long pollId,
			                     @WebParam(name="pollItemId")Long pollItemId) {
		//return pollService.vote(RequestContext.getContext(), pollItemId);
		return pollService.vote(context, pollId, pollItemId);
	}
	
	@WebResult(name="participant")
	public PollParticipant addParticipant (@WebParam(name="context")RequestContext context, 
	                                       @WebParam(name="email")String email, 
	                                       @WebParam(name="pollId")Long pollId) {
		return pollService.addParticipant(context, email, pollId);
	}
	
	@WebResult(name="item")
	public PollItem addItem (@WebParam(name="context")RequestContext context, 
	                         @WebParam(name="text")String text,
	                         @WebParam(name="pollId")Long pollId) {
		return pollService.addItem(context, text, pollId);
	}
	
	@WebResult(name="poll")
	public List<Poll> findMyPolls (@WebParam(name="context")RequestContext context, 
	                               @WebParam(name="startDate")Date start, 
	                               @WebParam(name="endDate")Date end) {
		return pollService.findMyPolls(context, start, end);
		
	}
	
	@WebResult(name="poll")
	public List<Poll> findParticipantPolls (@WebParam(name="context")RequestContext context, 
	                                        @WebParam(name="startDate")Date start, 
	                                        @WebParam(name="endDate")Date end) {
		return pollService.findParticipantPolls(context, start, end);
	}
	
	@WebResult(name="poll")
	public List<Poll> findPublicPolls (@WebParam(name="context")RequestContext context,
	                                   @WebParam(name="startDate")Date start,
	                                   @WebParam(name="endDate")Date end) {
		return pollService.findPublicPolls(context, start, end);
	}

}
